#ifndef SERVER_H
#define SERVER_H

#include "game.h"
#include "websocket.h"
#include <atomic>
#include <thread>
#include <unordered_map>

class GameServer {
public:
    GameServer(int gameWidth, int gameHeight, int port);
    ~GameServer();
    
    void start();
    void stop();
    
private:
    void gameLoop();
    void handleMessage(websocketpp::connection_hdl hdl, const std::string& message);
    
    Game game_;
    WebSocketService webSocketService_;
    std::atomic<bool> running_;
    std::thread gameThread_;
    
    // 使用连接指针作为键
    std::unordered_map<void*, int> playerConnections_;
    int nextPlayerId_;
};

#endif // SERVER_H